package cn.com.gf.cmp.am.monitor.entrust;

import java.math.BigDecimal;
import java.util.Map;

import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate; 

 
public class EntrustSourceContext {
	
	 
	private long serialNo = 0L;  
	 
	  
	private String SELECT_SQL;
	 
	private String branch_no;

 
	public EntrustSourceContext(String branch_no) {
		super();
		this.branch_no = branch_no;
	}

	public long getSerialNo(JdbcTemplate jdbcTemplate,String entrustKafkaTable) {
		
		//serialNo=0，取当天最大的serial_no为初始值
		if(serialNo==0){ 
			 SELECT_SQL="select max(serial_no) as SERIAL_NO from "+entrustKafkaTable+" where branch_no="+branch_no+" and  l_date="+DateTime.now().toString("yyyyMMdd");
			 Map<String,Object> result=jdbcTemplate.queryForMap(SELECT_SQL);
			 
			 if(result!=null &&!result.isEmpty()){ 
				 try{
					 Object o=result.get("SERIAL_NO"); 
					 serialNo=((BigDecimal)(o!=null?o:0L)).longValue();
					 
				 }catch(Exception e){
					 
				 }
			 }		 
		}
		return serialNo;
	} 

	public void setSerialNo(long serialNo) {
		this.serialNo = serialNo;
	}
	 
	
	 
}
